<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../../include/admincontent.jsp" %>
<div id="Content">
    <form id="modelform" method="post" action="/Do/BS/EditExamAction">
        <input type="hidden" name="id" value="${exam.id}"/>
        <div class="toolbars">
            <a id="save">
                <em class="ico16 save_traft_16"></em>
                <span class="menu_span" title="保存">保存</span>
            </a>
        </div>
        <table class="treeTable inputform" style="margin-top: 10px">
            <tbody>
            <tr>
                <td width="90">选择考场:</td>
                <td width="400" style="border-right:none;">
                    <div><select name="roomid" datatype="*" nullmsg="考场不能为空">${room}</select><input type="hidden"
                                                                                                    value="${exam.roomid}"/>
                    </div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>考场座位数:</td>
                <td style="border-right:none;" id="seat"></td>
                <td></td>
            </tr>
            <tr>
                <td>考试开始时间:</td>
                <td style="border-right:none;">
                    <div><input type="text" name="starttime" value="${exam.starttime}" class="select" datatype="*"
                                nullmsg="考试开始时间不能为空" onFocus="blur()"
                                onclick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})"/></div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>考试截止时间:</td>
                <td style="border-right:none;">
                    <div><input type="text" name="endtime" value="${exam.endtime}" class="select" datatype="*"
                                nullmsg="考试截止时间不能为空" onFocus="blur()"
                                onclick="laydate({istime: true,format:'YYYY-MM-DD hh:mm'})"/></div>
                </td>
                <td></td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('select').each(function () {
            $(this).val($(this).next().val());
        });
        getseat();
        $('select[name=roomid]').change(function () {
            getseat();
        });

        $('#save').click(function () {
            var data = {};
            data["roomid"] = $("select[name = 'roomid']").val();
            data["starttime"] = $("input[name = 'starttime']").val();
            data["endtime"] = $("input[name = 'endtime']").val();

            if (data["starttime"] == "" || data["endtime"] == ""){
                layer.msg("起始時間不能为空", {icon: 2});
                return;
            }
            $.ajax({
                url: "/Do/BS/AddExamAction",
                type: 'POST',
                data: data,
                success: function (data) {
                    if (data.state){
                        layer.msg(data.Message, {icon: 1});
                        parent.location.reload();
                    }else {
                        layer.msg(data.Message, {icon: 2});
                    }

                },
                error: function (data) {
                    layer.msg(data.Message, {icon: 2});
                }
            });
        });
    });

    function getseat() {
        getAjax('/Do/BS/getseatcount?id=' + $('select[name=roomid]').val(), null, function (data) {
            $('#seat').html(data);
        });
    }
</script>
</body>
</html>